var a = require("../../../../mybehaviors/location/location"), t = getApp();

Component({
    behaviors: [ a ],
    properties: {
        params: {
            type: null
        }
    },
    data: {
        stores: [],
        address: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        showMore: !1,
        page: 1,
        total_page: 0,
        loading: !0,
        language: ""
    },
    lifetimes: {
        attached: function() {
            var a = wx.getStorageSync("langIndex");
            this.setData({
                language: a.en
            });
        },
        moved: function() {},
        detached: function() {}
    },
    attached: function() {},
    ready: function() {
        var a = this;
        this._getLocation(function() {
            a.getStores();
        });
    },
    pageLifetimes: {
        show: function() {},
        hide: function() {},
        resize: function() {}
    },
    methods: {
        toGood: function(a) {
            var t = a.currentTarget.dataset.goods_id;
            wx.navigateTo({
                url: "/packageA/detail_v2/detail_v2?id=" + t
            });
        },
        getStores: function() {
            var a = this, e = t.getNetAddresss("plugin.store-cashier.frontend.store.store.get-store-list-to-page"), o = t.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
            e += "&page=" + a.data.page, e += "&lng=" + (o.lng ? o.lng : ""), e += "&lat=" + (o.lat ? o.lat : ""), 
            e += "&kwd=", e += "&city_name=" + this.data.city, e += "&pagesize=" + this.data.params.num, 
            e += "&showshop=" + this.data.params.showshop, t._getNetWork({
                url: e,
                success: function(t) {
                    var e = t.data;
                    1 == e.result && (a.setData({
                        showMore: !0,
                        stores: e.data.data
                    }), e.data.last_page ? a.setData({
                        total_page: e.data.last_page
                    }) : e.data.lastPage && a.setData({
                        total_page: e.data.lastPage
                    }), a.data.page >= a.data.total_page ? a.setData({
                        loading: !1
                    }) : a.setData({
                        loading: !0
                    }));
                },
                fail: function(a) {
                    console.log(a.msg);
                }
            });
        },
        toRouter: function(a) {
            var t = a.currentTarget.dataset.items.specify_show, e = a.currentTarget.dataset.items.id;
            1 == t ? wx.navigateTo({
                url: "/packageC/o2o/o2oStore/o2oStore?store_id=" + e
            }) : wx.navigateTo({
                url: "/packageC/o2o/HomeSeller/HomeSeller?store_id=" + e
            });
        },
        toClassify: function(a) {
            var t = a.currentTarget.dataset.id, e = a.currentTarget.dataset.name;
            wx.navigateTo({
                url: "/packageC/o2o/o2oCategory/o2oCategory?id=" + t + "&city=" + this.data.city + "&point=" + JSON.stringify(this.data.point) + "&name=" + e
            });
        },
        gophone: function(a) {
            var t = a.currentTarget.dataset.mobile;
            wx.makePhoneCall({
                phoneNumber: t
            });
        },
        goToAdress: function(a) {
            var e = a.currentTarget.dataset.items.latitude, o = a.currentTarget.dataset.items.longitude, s = a.currentTarget.dataset.items.store_name, i = t.BMapTransqqMap(parseFloat(o), parseFloat(e));
            wx.openLocation({
                latitude: i.lat,
                longitude: i.lng,
                scale: 18,
                name: s
            });
        },
        getMoreStores: function() {
            var a = this;
            if (this.data.page != this.data.total_page) if (this.data.page > this.data.total_page) a.setData({
                loading: !1
            }); else {
                a.setData({
                    page: this.data.page + 1
                });
                var e = t.getNetAddresss("plugin.store-cashier.frontend.store.store.get-store-list-to-page"), o = t.qqMapTransBMap(parseFloat(this.data.point.lng), parseFloat(this.data.point.lat));
                e += "&page=" + this.data.page, e += "&lng=" + (o.lng ? o.lng : ""), e += "&lat=" + (o.lat ? o.lat : ""), 
                e += "&kwd=", e += "&city_name=" + this.data.city, e += "&pagesize=" + this.data.params.num, 
                e += "&showshop=" + this.data.params.showshop, t._getNetWork({
                    url: e,
                    success: function(t) {
                        var e = t.data;
                        if (1 == e.result) {
                            var o = a.data.stores;
                            a.setData({
                                stores: o.concat(e.data.data)
                            }), a.data.page == a.data.total_page && a.setData({
                                loading: !1
                            });
                        } else a.setData({
                            page: a.data.page - 1,
                            loading: !1
                        });
                    },
                    fail: function(a) {
                        console.log(a);
                    }
                });
            } else a.setData({
                loading: !1
            });
        }
    }
});